//------------------------------------------------------------------------------
// Original code by Christian Graus, modified by Ste Brennan for DNAide. 
// http://www.codeproject.com/cs/media/csharpfilters.asp
//------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace DNAide.Drawing
{
	public static partial class BitmapAide
	{
		
		/// <summary>
		/// Smooth
		/// </summary>
		/// <remarks>Default weight = 1</remarks>
		/// <param name="bitmap"></param>
		public static void Smooth(Bitmap bitmap)
		{
			Smooth(bitmap, 1);
		}

		/// <summary>
		/// Smooth
		/// </summary>
		/// <param name="bitmap"></param>
		/// <param name="weight"></param>
		public static void Smooth(Bitmap bitmap, Int32 weight)
		{
			ConvMatrix m = new ConvMatrix();
			m.SetAll(1);
			m.Pixel = weight;
			m.Factor = weight + 8;

			Conv3x3(bitmap, m);
		}


		/// <summary>
		/// Locate significant color transitions in an image, then create intermediary colors to soften the edges
		/// </summary>
		/// <remarks>Default weight = 4</remarks>
		/// <param name="bitmap"></param>
		public static void GaussianBlur(Bitmap bitmap)
		{
			GaussianBlur(bitmap, 4);
		}

		/// <summary>
		/// Locate significant color transitions in an image, then create intermediary colors to soften the edges
		/// </summary>
		/// <param name="bitmap"></param>
		/// <param name="weight"></param>
		public static void GaussianBlur(Bitmap bitmap, Int32 weight)
		{
			ConvMatrix m = new ConvMatrix();
			m.SetAll(1);
			m.Pixel = weight;
			m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 2;
			m.Factor = weight + 12;

			Conv3x3(bitmap, m);
		}


		/// <summary>
		/// A sharpen type filter
		/// </summary>
		/// <remarks>Default weight = 9</remarks>
		/// <param name="bitmap"></param>
		public static void MeanRemoval(Bitmap bitmap)
		{
			MeanRemoval(bitmap, 9);
		}

		/// <summary>
		/// A sharpen type filter
		/// </summary>
		/// <param name="bitmap"></param>
		/// <param name="weight"></param>
		public static void MeanRemoval(Bitmap bitmap, Int32 weight)
		{
			ConvMatrix m = new ConvMatrix();
			m.SetAll(-1);
			m.Pixel = weight;
			m.Factor = weight - 8;

			Conv3x3(bitmap, m);
		}

		/// <summary>
		/// Sharpen
		/// </summary>
		/// <remarks>Default weight = 11</remarks>
		/// <param name="bitmap"></param>
		public static void Sharpen(Bitmap bitmap)
		{
			Sharpen(bitmap, 11);
		}

		/// <summary>
		/// Sharpen
		/// </summary>
		/// <param name="bitmap"></param>
		/// <param name="weight"></param>
		public static void Sharpen(Bitmap bitmap, Int32 weight)
		{
			ConvMatrix m = new ConvMatrix();
			m.SetAll(0);
			m.Pixel = weight;
			m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = -2;
			m.Factor = weight - 8;

			Conv3x3(bitmap, m);
		}


		/// <summary>
		/// Emboss
		/// </summary>
		/// <param name="bitmap"></param>
		public static void EmbossLaplacian(Bitmap bitmap)
		{
			ConvMatrix m = new ConvMatrix();
			m.SetAll(-1);
			m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0;
			m.Pixel = 4;
			m.Offset = 127;

			Conv3x3(bitmap, m);
		}
	}

}